home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / tcp / mufs_telnetd.lha / telnetd2_0.lha / telnetd-2.0 / source / TnServ.c < prev    next >
C/C++ Source or Header  |  1995-04-13  |  4KB  |  109 lines

  1. /*
  2.  *      $Filename: TnServ.c $
  3.  *      $Revision: 2.0 $
  4.  *      $Date: 1995/04/13 19:53:48 $
  5.  *
  6.  *      Copyright (C) 1993,94 by Steve Holland <sdh4@cornell.edu>
  7.  *      Copyright (C) 1995 by Peter Simons <simons@peti.rhein.de>
  8.  *
  9.  *      This program is free software; you can redistribute it and/or
  10.  *      modify it under the terms of the GNU General Public License as
  11.  *      published by the Free Software Foundation; either version 2 of
  12.  *      the License, or (at your option) any later version.
  13.  *
  14.  *      This program is distributed in the hope that it will be useful,
  15.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.  *      General Public License for more details.
  18.  *
  19.  *      You should have received a copy of the GNU General Public License
  20.  *      along with this program; if not, write to the Free Software
  21.  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  *
  23.  *      $Id: TnServ.c 2.0 1995/04/13 19:53:48 simons Exp $
  24.  *
  25.  */
  26.  
  27. /************************************* includes ***********/
  28. #include <sys/types.h>
  29. #include <sys/socket.h>
  30. #include <netinet/in.h>
  31. #include <proto/socket.h>
  32. #include <netdb.h>
  33. #include <errno.h>
  34. #include <dos/dos.h>
  35. #include <dos/dostags.h>
  36. #include <proto/dos.h>
  37. #include <proto/exec.h>
  38. #include <clib/netlib_protos.h>
  39.  
  40. #include <stdio.h>
  41. #include <string.h>
  42. #include <stdlib.h>
  43.  
  44. #include "TnServ_rev.h"
  45.  
  46. /************************************* defines ************/
  47.  
  48. /************************************* global variables ***/
  49. static const char __DOSVer[] = VERSTAG " written by Peter Simons <simons@peti.rhein.de>";
  50.  
  51. int main(void)
  52. {
  53.         struct servent *sp;
  54.         struct sockaddr_in ServAddr;
  55.         LONG Socket, SubSock, SubSockID;
  56.         int WaitSig;
  57.         static char ArgStr[200];
  58.         BPTR TelNetProg;
  59.         long Len;
  60.  
  61.         if (!(sp = getservbyname("telnet", "tcp")))
  62.                 return 21;
  63.  
  64.         bzero(&ServAddr, sizeof(ServAddr));
  65.         ServAddr.sin_port = sp->s_port;
  66.         ServAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  67.         ServAddr.sin_family = AF_INET;
  68.         ServAddr.sin_len = sizeof(ServAddr);
  69.         Socket = socket(AF_INET, SOCK_STREAM, 0);
  70.         if (Socket < 0)
  71.                 return 22;
  72.         bind(Socket, (struct sockaddr *) &ServAddr, sizeof(ServAddr));
  73.         listen(Socket, 5);
  74.         WaitSig = AllocSignal(-1);
  75.         if (WaitSig == -1)
  76.                 return 23;
  77.  
  78.         for (;;) {
  79.                 Len = sizeof(ServAddr);
  80.                 SubSock = accept(Socket, (struct sockaddr *) &ServAddr, &Len);
  81.                 if (SubSock < 0) {
  82.                         if (Errno() == EINTR) {
  83.                                 CloseSocket(Socket);
  84.                                 return 0;
  85.                         }
  86.                         continue;
  87.                 }
  88.                 SetSignal(0, (1 << WaitSig));   /* unset WaitSig signal */
  89.                 SubSockID = ReleaseSocket(SubSock, UNIQUE_ID);
  90.                 sprintf(ArgStr, "%u %u %u", (unsigned long) SubSockID, (unsigned long) WaitSig, (unsigned long) FindTask(NULL));
  91.                 if (TelNetProg = LoadSeg("AmiTCP:serv/telnetd")) {
  92.                         if (CreateNewProcTags(NP_Seglist, TelNetProg,
  93.                                                 NP_Name, "telnet login",
  94.                                                 NP_Arguments, ArgStr,
  95.                                                 NP_StackSize, 12000,
  96.                                                 NP_FreeSeglist, TRUE,
  97.                                                 TAG_END)) {
  98.  
  99.                                 /* CreateProc("telnet login",0,TelNetProg,12000); */
  100.                                 Wait(1 << WaitSig);     /* Wait for new proc to start up */
  101.                         }
  102.                 }
  103.         }
  104.  
  105. }
  106.  
  107.  
  108. /************************************* subroutines ********/
  109.